angular.module("vehicleCheckApp", ["ionic",'ngCordova','globalService','_vehicleData', '_DBSerive'])

 .run(function($ionicPlatform,$rootScope,$location,$ionicHistory,$state,$cordovaKeyboard,$cordovaToast) {
        $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleLightContent();
    }
    window.addEventListener('native.keyboardshow', function(){
        document.body.classList.add('keyboard-open');
    });

    //免登录
    var remember = localStorage.remember;
    if(remember && remember == "true"){
      // console.log('aaa')
        $state.go("vehicleCheck");
    }
        });

    $ionicPlatform.registerBackButtonAction(function (e) {
        //首页按返回键退出
        if ($location.path() == '/vehicleCheck') {
            if ($rootScope.backButtonPressedOnceToExit) {
                ionic.Platform.exitApp();
            } else {
                $rootScope.backButtonPressedOnceToExit = true;
                $cordovaToast.showShortCenter('再按一次退出系统');
                setTimeout(function () {
                    $rootScope.backButtonPressedOnceToExit = false;
                }, 2000);
            }
        }
        else if ($ionicHistory.backView()) {
            if($cordovaKeyboard.isVisible()){
                $cordovaKeyboard.close();
            }else{
                $ionicHistory.goBack();
            }
        } else {
            $rootScope.backButtonPressedOnceToExit = true;
            $cordovaToast.showShortCenter('再按一次退出系统');
            setTimeout(function () {
                $rootScope.backButtonPressedOnceToExit = false;
            }, 2000);
        }
        e.preventDefault();
        return false;
    }, 101);

})

.config(function($stateProvider, $urlRouterProvider, $ionicConfigProvider) {
	$ionicConfigProvider.navBar.alignTitle("center");
	$ionicConfigProvider.views.maxCache(0);

  $stateProvider
    .state('login', {
    url: "/login",    
    templateUrl: "templates/login.html",
    controller: 'LoginCtrl'
    })

  	.state('vehicleCheck', {
    url: "/vehicleCheck",    
    templateUrl: "templates/vehicleCheck.html",
    controller: 'VehicleCtrl',
	params:{transporter:null}
  	})

  	.state('transporter', {
    url: "/transporter",    
    templateUrl: "templates/transporter.html",
    controller: 'TransporterCtrl'
  	})

  	.state('checklist', {
    url: "/checklist",    
    templateUrl: "templates/checklist.html",
    controller: 'ChecklistCtrl'
  	})

  	.state('checklistPreview', {
    url: "/checklistPreview/:revise/:index",    
    templateUrl: "templates/checklistPreview.html",
    controller: 'ChecklistPreviewCtrl'
  	})

  	.state('checklistResult', {
    url: "/checklistResult/:resultText/:resultTextCss",    
    templateUrl: "templates/checklistResult.html",
    controller: 'ChecklistResultCtrl'
  	})

  	.state('pendinglist', {
    url: "/pendinglist/:revise",    
    templateUrl: "templates/pendinglist.html",
    controller: 'PendinglistCtrl'
  	})

    .state('update', {
    url: "/update/:warehouseName",    
    templateUrl: "templates/update.html",
    controller: 'UpdateCtrl'
    })

    .state("changePwd",{
          url:"/changePwd",
          templateUrl:"templates/changePwd.html",
          controller:'UpdateCtrl'
      });

   $urlRouterProvider.otherwise('/login');

});